import json
import requests
from urllib3.exceptions import InsecureRequestWarning
import datetime

today = datetime.date.today()  # 今天
yester = today - datetime.timedelta(days=1)
yesterday = str(yester).replace('-', '')
# 禁用安全请求警告
Platform = "西瓜阅读_轻吧小说"


def xigua1():
    try:
        requests.urllib3.disable_warnings(InsecureRequestWarning)
        r = requests.session()
        url = "https://www.dzids.cn/admin/index/login?url=%2Fadmin"
        date = {
            "username": "",
            "password": ""
        }
        rr = r.post(url=url, data=date, verify=False, timeout=15)
        header = {
            "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36",
            "X-Requested-With": "XMLHttpRequest"
        }
        aa = r.get(url="https://www.dzids.cn/admin/collect/index?limit=10", headers=header, verify=False, timeout=15)
        html = json.loads(aa.text)
        for y in range(len(html["rows"])):
            if str(yesterday) == str(html["rows"][y]["createdate"]):
                date_time = html["rows"][y]["createdate"]
                Amount_share = html["rows"][y]["recharge_money_benefit"]
                return date_time, Amount_share, Platform
            else:
                if y == len(html["rows"]) - 1:
                    return '', 'None', Platform
                else:
                    pass
    except Exception:
        print("获取 西瓜阅读_轻吧小说 数据失败")
        return '', 'None', Platform
    except ConnectionError:
        print("获取 西瓜阅读_轻吧小说 数据 超时")
        return '', 'None', Platform
